package com.ssy.service.impl;

import cn.hutool.core.util.NumberUtil;
import com.ssy.common.CodeMsg;
import com.ssy.common.PageInfo;
import com.ssy.common.Result;
import com.ssy.dao.CurriculumDao;
import com.ssy.service.CurriculumService;
import com.ssy.vo.CurriculumVo;

import java.util.HashMap;

/**
 * curriculumServiceImpl
 *
 * @author ssy
 * @date 2020/11/19
 **/
public class CurriculumServiceImpl implements CurriculumService {

    CurriculumDao curriculumDao = new CurriculumDao();

    @Override
    public int queryCurriculumByClassIdAndCourseId(int classNameId, int courseNameId) {
        return this.curriculumDao.queryCurriculumByClassIdAndCourseId(classNameId, courseNameId);
    }

    @Override
    public Result bathDelCurriculum(String[] ids) {
        boolean flag = this.curriculumDao.batchDeleteCurriculum(ids);
        return flag ? new Result(CodeMsg.DELETE_SUCCES) : new Result(CodeMsg.DELETE_ERROR);
    }

    @Override
    public Result deleteCurriculum(String id) {
        int id1 = Integer.parseInt(id);
        boolean flag = this.curriculumDao.deleteOneCurriculum(id1);
        return flag ? new Result(CodeMsg.DELETE_SUCCES) : new Result(CodeMsg.DELETE_SUCCES);
    }

    @Override
    public Result updateCurriculm(String workId, String number, String courseId, String teacher, String classId, String address, String startTime, String cumId) {
        int workId1 = Integer.parseInt(workId);
        int number1 = Integer.parseInt(number);
        int courseId1 = Integer.parseInt(courseId);
        int classId1 = Integer.parseInt(classId);
        int cumId1 = Integer.parseInt(cumId);
        boolean flag = this.curriculumDao.updateCurriculm(workId1, number1, courseId1, classId1, teacher, address, startTime, cumId1);
        return flag ? new Result(CodeMsg.UPDATE_SUCCES) : new Result(CodeMsg.UPDATE_ERROR);
    }

    @Override
    public Result addCurriculm(String workId, String number, String courseId, String teacher, String classId, String address, String startTime) {
        int workId1 = Integer.parseInt(workId);
        int number1 = Integer.parseInt(number);
        int courseId1 = Integer.parseInt(courseId);
        int classId1 = Integer.parseInt(classId);
        boolean flag = this.curriculumDao.insertCurriculm(workId1, number1, courseId1, classId1, teacher, address, startTime);
        return flag ? new Result(CodeMsg.ADD_SUCCES) : new Result(CodeMsg.ADD_ERROR);

    }

    @Override
    public Result selectAllCourseList() {
        return this.curriculumDao.queryAllCourseList();
    }

    @Override
    public Result queryPage(HashMap<String, Object> param, String page, String limit) {
        Integer pageNo = NumberUtil.isNumber(page) ? Integer.parseInt(page) : 1;
        Integer limitNo = NumberUtil.isNumber(limit) ? Integer.parseInt(limit) : 10;
        PageInfo<CurriculumVo> userPageInfo = this.curriculumDao.selectPage(param, pageNo, limitNo);
        return new Result(userPageInfo);
    }
}
